package com.eascs.spider.ant.schdule.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.eascs.spider.ant.common.proj.Task;
import com.eascs.spider.ant.schdule.dispatcher.Dispatcher;
import com.eascs.spider.ant.schdule.register.RegisterCentre;

@RestController
@RequestMapping("/schdule")
public class Controller {

	private static Logger logger = LoggerFactory.getLogger(Controller.class);
	@Autowired
	RegisterCentre register;
	
	@Autowired
	Dispatcher dispatcher;
	
	/**
	 * 首页爬取请求入口
	 * @param url
	 */
	@RequestMapping(value = "/entrance" ,method = RequestMethod.GET)  
    public void recieve(String url) {  
		logger.info("调度中心entrance入口：{}" ,url);
        Task task = new Task();
        task.setHomepage(Task.HOMEPAGE_YES);;//主页
        task.setUrl(url);
        dispatcher.addHomepageTask(task);
	}
	
	/**
	 * 接收从工作节点发送过来的任务
	 * @param task
	 */
	@RequestMapping(value = "/worker" , method = RequestMethod.POST)
	public void recieveFromWorker(Task task){
		dispatcher.addTask(task);
	}
	
}
